package com.zry.pda.ui.base

import android.app.Dialog
import android.content.pm.ActivityInfo
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.os.Bundle
import android.view.Window
import com.zry.pda.animation.RecyclerViewUtilKt
import com.zry.pda.config.MyActivityManager
import com.zry.pda.config.MyApplication
import com.zry.pda.greendao.gen.FlowRecordInfoDao
import com.zry.pda.greendao.gen.OutTreasuryCodeDao
import com.zry.pda.greendao.gen.PackingOperationInfoDao
import com.zry.pda.greendao.gen.PutStorageCodeDao
import com.zry.pda.retrofit.ApiSupport
import com.zry.pda.utils.ToastUtil


abstract class BaseActivity : PermissionActivity(), ApiSupport {
    var myApplication: MyApplication? = null
    var recyclerViewUtilKt: RecyclerViewUtilKt? = null
    var myActivityManager: MyActivityManager? = null
    var loadingDialog: Dialog? = null
    var viewDataBinding: ViewDataBinding? = null

    var outTreasuryCodeDao: OutTreasuryCodeDao? = null
    var flowRecordInfoDao: FlowRecordInfoDao? = null
    var putStorageCodeDao: PutStorageCodeDao? = null
    var packingOperationInfoDao: PackingOperationInfoDao? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
        viewDataBinding = getDataBinding()





        myActivityManager = MyActivityManager.getActivityManager()
        myActivityManager?.addActivity(this)
        myActivityManager?.addPermissionActivity(this)
        myApplication = MyApplication.instance()
        //禁止横竖屏切换
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

        loadingDialog = ToastUtil.loadingDialog(this)


        outTreasuryCodeDao = myApplication?.getDaoSession()!!.outTreasuryCodeDao
        flowRecordInfoDao = myApplication?.getDaoSession()!!.flowRecordInfoDao
        putStorageCodeDao = myApplication?.getDaoSession()!!.putStorageCodeDao
        packingOperationInfoDao = myApplication?.getDaoSession()!!.packingOperationInfoDao


        initData()
    }


    private fun getDataBinding(): ViewDataBinding {
        return DataBindingUtil.setContentView(this, getLayoutId())
    }

    protected abstract fun getLayoutId(): Int
    protected abstract fun initData()



    protected fun toast(toastMessage: String) {
        ToastUtil.toast(this, toastMessage)
    }


    override fun onDestroy() {
        super.onDestroy()
        myActivityManager?.removePermissionActivity(this)
        myActivityManager?.finishActivity()
    }
}
